import configparser
import os
import socket
import platform

class Config:
    conf = ""

    def __init__(self,basepath=""):
        sys_platform = platform.platform().lower()
        print(sys_platform)
        if basepath == "":
            basepath = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
        else:
            pass
        if sys_platform.find("windows") >= 0:
            cfgpath = basepath + "\\application.ini"
        else:
            cfgpath = basepath + "/application.ini"

        # 创建管理对象
        self.conf = configparser.ConfigParser()
        # 读ini文件
        self.conf.read(cfgpath, encoding="utf-8")  # python3
        env = self.conf.get("application", "active")
        self.env = env
        print(env)
        if sys_platform.find("windows") >= 0:
            cfgpath = basepath + "\\application-" + env + ".ini"
        else:
            cfgpath = basepath + "/application-" + env + ".ini"
        self.conf = configparser.ConfigParser()
        # 读ini文件
        self.conf.read(cfgpath, encoding="utf-8")  # python3

    def getApi(self):
        return {
            "host": self.conf.get("api", "host"),
            "base": self.conf.get("api","base"),
            "cluster_mark_id": self.conf.get("api", "cluster_mark_id")
        }

    def getCloudDataDB(self):
        return [self.conf.get("cloud_data", "host"),
                self.conf.get("cloud_data", "user"),
                self.conf.get("cloud_data", "pass"),
                self.conf.getint("cloud_data", "port"),
                self.conf.get("cloud_data", "dbname")
                ]

    def getCloudDeskDB(self):
        return [self.conf.get("cloud_desk", "host"),
                self.conf.get("cloud_desk", "user"),
                self.conf.get("cloud_desk", "pass"),
                self.conf.getint("cloud_desk", "port"),
                self.conf.get("cloud_desk", "dbname")
                ]

    def getVdc(self):
        return {
                "host":self.conf.get("vdc", "host"),
                "user":self.conf.get("vdc", "user"),
                "pass":self.conf.get("vdc", "pass")
                }


